<?php

/**

 * Some people get confused, and think factories/modules ARE stand-alone

 * plugins. If they try to activate this factory as if it was a plugin, they will

 * be shown a message explaining how to install aLinks.

 */

if (!defined('ALINKS_RUNNING')) {

	/**

	Plugin Name: Fancy Tooltips Factory

	Description: aLinks factory component

	*/

	add_action('admin_notices', create_function(null, '

	?>

	<div id="alinks_notice" class="updated fade-ff0000">

		<p><strong>Error</strong><br />

		You activated an aLinks factory as a plugin. It is a component of the aLinks. It is not a WordPress plugin. You must have aLinks installed to

		use this.</p><p>You can download aLinks from <a href="http://alinks.headzoo.com/download">here</a>. Once you have aLinks installed

		and activated, you can install this factory following the directions in the <a href="http://alinks.headzoo.com/documentation">documentation</a>.</p?

	</div>

	<?php

	'));

	return;

}



/**

 * @see Alinks_Factory_Abstract

 */

require_once('Alinks/Factory/Abstract.php');



/**

 * Fancy Tooltips Factory

 *

 * @author Sean Hickey <sean@headzoo.com>

 * @version $Id: factory.php 425 2008-07-09 16:27:54Z sean $

 */

class Alinks_Factory_FancyTooltips extends Alinks_Factory_Abstract

{

	/**

	 * The name of the factory

	 *

	 * @var string

	 */

	protected $_name = 'Fancy Tooltips';

	

	/**

	 * The factory safe name

	 *

	 * @var string

	 */

	protected $_safe_name = 'fancy_tooltips';

	

	/**

	 * The URL for the factory

	 *

	 * @var string

	 */

	protected $_url = 'http://alinks.headzoo.com/factories/fancy_tooltips';

	

	/**

	 * A short description of the factory

	 *

	 * @var string

	 */

	protected $_description = 'Creates links with fancy DHTML tooltips.';

	

	/**

	 * The factory authors

	 *

	 * @var array

	 */

	protected $_authors = array(

		array('name' => 'Sean Hickey', 'url' => 'http://headzoo.com'),

		array('name' => 'Walter Zorn', 'url' => 'http://www.walterzorn.com')

	);

	

	/**

	 * The factory version

	 *

	 * @var float

	 */

	protected $_version = 1.0;

	

	/**

	 * The version of aLinks the factory is compatible with

	 *

	 * @var string

	 */

	protected $_alinks_version = '2.*';

	

	/**

	 * Whether this factory has a settings form

	 *

	 * @var bool

	 */

	protected $_has_settings_form = true;

	

	/**

	 * Whether this factory has a keyphrases form

	 *

	 * @var bool

	 */

	protected $_has_keyphrases_form = true;

	

	/**

	 * Whether the JavaScript has been included

	 *

	 * @var bool

	 */

	protected $_script_added = false;

	

	/**

	 * Returns the form information for the keyphrases page

	 *

	 * @var Alinks_Form

	 */

	public function getKeyphrasesForm()

	{

		$form = new Alinks_Form($this);

		$phrase = new Alinks_Form_Element_Text('phrase', null, 'Phrase: ');

		$phrase->setRequired(true);

		$form->addElement($phrase);

		

		$description = new Alinks_Form_Element_Textarea('description', null, 'Description: ');

		$form->addElement($description);

		

		$url = new Alinks_Form_Element_Text('url', null, 'URL: ');

		$url->setDescription('The URL the clicked link will go to.');

		$url->setRequired(true);

		$form->addElement($url);

		

		return $form;

	}

	

	/**

	 * Returns the settings form for this factory

	 *

	 * @return Alinks_Form

	 */

	public function getSettingsForm()

	{

		$form = new Alinks_Form($this);

		$colors = array(

			'aqua' => 'Aqua',

			'black' => 'Black',

			'blue' => 'Blue',

			'fuchsia' => 'Fuchsia',

			'gray' => 'Gray',

			'green' => 'Green',

			'lime' => 'Lime',

			'maroon' => 'Maroon',

			'navy' => 'Navy',

			'olive' => 'Olive',

			'purple' => 'Purple',

			'red' => 'Red',

			'silver' => 'Silver',

			'teal' => 'Teal',

			'white' => 'White',

			'yellow' => 'Yellow'

		);

		

		$background_color = new Alinks_Form_Element_Select('background_color', null, 'Tooltip Background Color: ', $colors);

		$background_color->setDescription('The background color of the tooltip.');

		$form->addElement($background_color);

		

		$border_color = new Alinks_Form_Element_Select('border_color', null, 'Tooltip Border Color: ', $colors);

		$border_color->setDescription('The color of the tooltip border.');

		$form->addElement($border_color);

		

		$text_color = new Alinks_Form_Element_Select('font_color', null, 'Text Color: ',  $colors);

		$text_color->setDescription('The color of the tooltip text.');

		$form->addElement($text_color);

		

		$shadow = new Alinks_Form_Element_Checkbox('shadow', null, 'Drop Shadow: ');

		$shadow->setDescription('Tooltips will have a shadow.');

		$form->addElement($shadow);

		

		return $form;

	}

	

	/**

	 * Replaces a keyphrase with a link

	 *

	 * @param Alinks_Keyphrase_Interface $keyphrase The keyphrase

	 * @param Alinks_LinkBuilder_Interface $builder The link builder

	 * @return Alinks_LinkBuilder_Interface

	 */

	public function parse(Alinks_Keyphrase_Interface $keyphrase, Alinks_LinkBuilder_Interface $builder)

	{

		$description = addslashes($keyphrase->getDescription());

		$background_color = (isset($this->_settings['background_color']))

			? $this->_settings['background_color'] : 'green';

		$border_color = (isset($this->_settings['border_color']))

			? $this->_settings['border_color'] : 'black';

		$text_color = (isset($this->_settings['font_color']))

			? $this->_settings['font_color'] : 'white';

		$shadow = (isset($this->_settings['shadow']) && $this->_settings['shadow']) ? 'true' : 'false';

		

		$builder->addArg('onmouseover', "Tip('$description', WIDTH, 250, BGCOLOR, '$background_color', FONTCOLOR, '$text_color', BORDERCOLOR, '$border_color', SHADOW, $shadow)");

		$builder->addArg('onmouseout', 'UnTip()');

		if (false === $this->_script_added) {

			$home = Alinks_Registry::get('alinks_url') . '/factories/fancy_tooltips/wz_tooltip.js';

			$builder->addPreHtml('<script type="text/javascript" src="' . $home . '"></script>');

			$this->_script_added = true;

		}

		

		$builder->setUri($keyphrase->getOptions('url'));

	}

}

